package frsf.cidisi.exercise.tp1_ia.search.actions;

import frsf.cidisi.exercise.tp1_ia.search.*;
import frsf.cidisi.faia.agent.search.SearchAction;
import frsf.cidisi.faia.agent.search.SearchBasedAgentState;
import frsf.cidisi.faia.state.AgentState;
import frsf.cidisi.faia.state.EnvironmentState;

public class Cancel_DemandForecast extends SearchAction {

    /**
     * This method updates a tree node state when the search process is running.
     * It does not updates the real world state.
     */
	
	// TODO: Use this conditions
    // PreConditions: diasEsperando = 5
    // PostConditions: null
    
    @Override
    public SearchBasedAgentState execute(SearchBasedAgentState s) {
        EstadoAgente agState = (EstadoAgente) s;
        /*
        if(agState.getposicionAgente()==EstadoAgente.FORECAST_REQUEST_SENT){
        	agState.setposicionAgente(EstadoAgente.FORECAST_REQUEST_REFUSE);
        	return agState;
        }*/
        
        return null;
    }

    /**
     * This method updates the agent state and the real world state.
     */
    @Override
    public EnvironmentState execute(AgentState ast, EnvironmentState est) {
        EstadoAmbiente environmentState = (EstadoAmbiente) est;
        EstadoAgente agState = ((EstadoAgente) ast);

        // TODO: Use this conditions
        // PreConditions: diasEsperando = 5
        // PostConditions: null
        
        /*if(agState.getposicionAgente()==EstadoAgente.FORECAST_REQUEST_SENT &&
        		(agState.gettpoTranscurrido()>120 || 
        	     agState.getPerceptionName().equals("Refuse Forecast Request") ||
        	     agState.getPerceptionName().equals("Cancel Demand Forecast") ) ){*/
        if(agState.getposicionAgente()==EstadoAgente.FORECAST_REQUEST_SENT &&
        		(agState.getPerceptionName().equals("Refuse Forecast Request")) ){
            // Update the real world
            environmentState.setposicionAgente(EstadoAgente.FORECAST_REQUEST_REFUSE);
            // Update the agent state
        	agState.setposicionAgente(EstadoAgente.FORECAST_REQUEST_REFUSE);
                
            return environmentState;
        }

        return null;
    }

    /**
     * This method returns the action cost.
     */
    @Override
    public Double getCost() {
        return new Double(0);
    }

    /**
     * This method is not important for a search based agent, but is essensial
     * when creating a calculus based one.
     */
    @Override
    public String toString() {
        return "Refuse Forecast Request or Cancel Demand Forecast";
    }
}